(function(win){
   var $=win.$,doc=document;
   
   if(typeof QNR==="undefined")
      QNR={};
   
   function submit(options,callback){
        var url,data,o=options;
        if(typeof options!=="undefined")
           $.getJSON(o.url,o.data,function(data){
               callback(data);
           }); 
   }
   QNR.submit=submit;

	$.ajax({
		url:"../../getalluser",
		dataType:"json",
		success:function(data){
			for(i=0;i<data.length;i++){
				var color;
				var operate;
				if(data[i].status==1){
					color="<span class='green'>有效</span>";
					operate="<a href='javascript:void(0))' datatype='2'>禁用</a>";
				}else if(data[i].status==2){
					color="<span class='red'>禁用</span>";
					operate="<a href='javascript:void(0))' datatype='1'>启用</a>";
				}
				$("#container")
				.append("<tr id='"+data[i].uid+"'><td align='center' width='60'><span class='blue'>"+data[i].login_name+"</span></td><td align='center' width='80'>"+data[i].realname+"</td><td align='center' width='100'>"+color+"</td><td align='center' width='120'><span class='green'>"+data[i].overdue+"<span></td><td align='center' width='100'>"+operate+"<a href='javascript:void(0))' datatype='-1'>删除</a></td><td align='center' width='100'><a class='reset' href='javascript:void(0);' datatype='3'>重置</a></td><td align='center' width='100'><a href='javascript:void(0))'>查看</a></td></tr>");
			}
			$("a[datatype]").click(function(){
				var dt=$(this).attr("datatype");
				if(dt==="undefined"){
					return;
				}
				if(dt==-1){
					if(!confirm("你确定要删除么")){
						return;
					}
				}
				var he=$(this);
				var parent=$(this).closest('tr');
				var uid=parent.attr("id");
				$.ajax({
					url:"../../operateuser?uid="+uid+"&opt="+dt,
					success:function(data){
						if(dt==3){
							alert(data);
						}else if(dt==-1){
							parent.remove();
						}else if(dt==2){
							he.attr("datatype","1");
							he.html("启用");
							var tmp=parent.find(".green").first();
							tmp.attr("class","red");
							tmp.html("禁用");
						}else if(dt==1){
							he.attr("datatype","2");
							he.html("禁用");
							var tmp=parent.find(".red").first();
							tmp.attr("class","green");
							tmp.html("启用");
						}
					}
				})
			})
		}
	})
   
	$('.button').click(function(){
	            var height= $(parent.document.body).height(),width=$(parent.document.body).width();
	            $(parent.document).find('.layout').css({
	                'backgroundColor':'#eee',
	                'height'     :   height,
	                opacity      : 0.5
	            }).show();
	            var target=$(parent.document).find('div.page');
	            target.css({
	                left  :  (width-500)/2,
	                top   :  (height-400)/2
	            }).show();
	 })
	 
	 $(win).load(function(){
        $('tr').each(function(i){
       $(this).hover(function(){
           $(this).addClass('bgrey');
       },function(){
         $(this).removeClass('bgrey');
       })
     })  
   })
   
})(window);
